package com.ruoyi.mes.systembasic.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.systembasic.domain.SmesProcess;
import com.ruoyi.mes.systembasic.service.ISmesProcessService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工序管理Controller
 *
 * @author simpsense
 * @date 2020-11-30
 */
@RestController
@RequestMapping("/systembasic/process")
public class SmesProcessController extends BaseController
{
    @Autowired
    private ISmesProcessService smesProcessService;

    /**
     * 查询工序管理列表
     */
    @PreAuthorize("@ss.hasPermi('systembasic:process:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmesProcess smesProcess)
    {
        startPage();
        List<SmesProcess> list = smesProcessService.selectSmesProcessList(smesProcess);
        return getDataTable(list);
    }

    /**
     * 导出工序管理列表
     */
    @PreAuthorize("@ss.hasPermi('systembasic:process:export')")
    @Log(title = "工序管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SmesProcess smesProcess)
    {
        List<SmesProcess> list = smesProcessService.selectSmesProcessList(smesProcess);
        ExcelUtil<SmesProcess> util = new ExcelUtil<SmesProcess>(SmesProcess.class);
        return util.exportExcel(list, "process");
    }

    /**
     * 获取工序管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('systembasic:process:query')")
    @GetMapping(value = "/{processNo}")
    public AjaxResult getInfo(@PathVariable("processNo") String processNo)
    {
        return AjaxResult.success(smesProcessService.selectSmesProcessById(processNo));
    }

    /**
     * 新增工序管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:process:add')")
    @Log(title = "工序管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmesProcess smesProcess)
    {
        return toAjax(smesProcessService.insertSmesProcess(smesProcess));
    }

    /**
     * 修改工序管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:process:edit')")
    @Log(title = "工序管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmesProcess smesProcess)
    {
        return toAjax(smesProcessService.updateSmesProcess(smesProcess));
    }

    /**
     * 删除工序管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:process:remove')")
    @Log(title = "工序管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{processNos}")
    public AjaxResult remove(@PathVariable String[] processNos)
    {
        return toAjax(smesProcessService.deleteSmesProcessByIds(processNos));
    }
}